local nio = require("nio")
local a = nio.tests
local lib = require("neotest.lib")

describe("process lib", function()
  describe("running a process", function()
    a.it("returns exit code", function()
      local result = lib.process.run({ "sh", "-c", "exit 12" })
      assert.equal(12, result)
    end)
    a.it("records stdout", function()
      local _, data = lib.process.run({ "printf", "hello" }, { stdout = true })
      assert.equal("hello", data.stdout)
    end)
    a.it("doesn't records stdout", function()
      local _, data = lib.process.run({ "printf", "hello" })
      assert.Nil(data.stdout)
    end)
    a.it("records stderr", function()
      local _, data = lib.process.run({ "sh", "-c", "printf hello >& 2" }, { stderr = true })
      assert.equal("hello", data.stderr)
    end)
    a.it("doesn't record stderr", function()
      local _, data = lib.process.run({ "sh", "-c", "printf hello >& 2" })
      assert.Nil(data.stderr)
    end)
  end)
end)
